<template>
	<view class="container">
		<view class="item" v-if="auths.indexOf('add')>-1"  @click="pageActive('../views/cqqk','add')" >
			<image src="../../static/icon/cq.png" class="icon"></image>
			<view>出勤情况</view>
		</view>
		<view class="item" v-if="auths.indexOf('rate')>-1"  @click="pageActive('../views/sqmjpj','rate')" >
			<image src="../../static/icon/sqmjpj.png" class="icon"></image>
			<view>社区民警评价</view>
		</view>
		<view class="item" v-if="auths.indexOf('query')>-1" @click="pageActive('../views/fwqz/index','query')" >
			<image src="../../static/icon/fwqz.png" class="icon"></image>
			<view>服务群众</view>
		</view>
		<view class="item" v-if="auths.indexOf('query')>-1" @click="pageActive('../views/aqff','query')" >
			<image src="../../static/icon/aqff.png" class="icon"></image>
			<view>安全防范</view>
		</view>
		<view class="item" v-if="auths.indexOf('query')>-1" @click="pageActive('../views/zhtj','query')" >
			<image src="../../static/icon/zhtj.png" class="icon"></image>
			<view>综合统计</view>
		</view>
		<view class="item"  v-if="false"  @click="pageActive('../views/cjlwpj','rate')" >
			<image src="../../static/icon/cjlwpj.png" class="icon"></image>
			<view>村居“两委”评价</view>
		</view>
		<view class="item" v-if="auths.indexOf('rate')>-1"  @click="pageActive('../views/gzznw','rate')" >
			<image src="../../static/icon/gzznw.png" class="icon"></image>
			<view>工作站内务</view>
		</view>
		<view class="item" v-if="auths.indexOf('query')>-1" @click="pageActive('../views/xxcj/xxcj','query')" >
			<image src="../../static/icon/xxcj.png" class="icon"></image>
			<view>信息采集</view>
		</view>
		<view class="item" v-if="auths.indexOf('query')>-1" @click="pageActive('../views/xssb/index','query')" >
			<image src="../../static/icon/xs.png" class="icon"></image>
			<view>线索上报</view>
		</view>
			
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {mapState,mapMutations} from 'vuex'
	export default {
		computed:mapState(['user', ]),
		data() {
			return {
				auths:[],
				maxWidth:''
			}
		},
		methods: {
			...mapMutations(['setJwzls','setGzzs']),
			pageActive(path,needAuth){
				let user = this.user.user;
				let res;
				//检查权限
				if(user && user.auths){
					res = user.auths.find(auth=> needAuth===auth)
				}
				if(res){
					uni.navigateTo({
						url:path,
					})
				}else{
					this.$refs.uToast.show({
						title: '当前页面无权限访问！',
						type: 'error'
					}) 
				}
				
				
			},
			//初始化下级警务助理+当前用户
			subjwzlInit(){
				this.$http.get("/user/getSubUsers",{params:{deptCode:this.user.user.deptCode}}).then(res=>{
					let data = res.data.data;
					let jwzlData = []
					if(data){
						jwzlData = this.parseListData(data);
					}
					let current = {
						label:this.user.user.name,
						value:this.user.user.id
					}
					jwzlData.unshift(current);
					this.setJwzls(jwzlData);
				}).catch(e=>{
					
				})
			},
			gzzMcInit(){
				
				this.$http.get("/gzznw/gzzs").then(res=>{
					let data = res.data.data;
					if(data){
						this.setGzzs(data);
					}
				}).catch(e=>{
				
				})
				
			},
			parseListData(data){
				let list = [];
				for(let v of data){
					let a = {};
					a.label = v.name;
					a.value = v.id;
					list.push(a);
				}
				return list;
			}
		},
		onLoad() {
			this.auths = this.user.user.auths;
			this.subjwzlInit();
			this.gzzMcInit();
			this.$auth.checkLocationAuth();
			this.maxWidth = uni.getSystemInfoSync().windowWidth
		},
		onShow() {
			
		}
	}
</script>

<style>
	.container {
		padding: 37rpx;
		font-size: 14px;
		line-height: 24px;
		column-count: 2;
		width: 100%;

	}
	.item{
		text-align: center;
		page-break-inside:avoid;
		overflow: auto;
		border: #007AFF solid 1px;
		border-radius: 5px;
		padding: 5px;
		margin-bottom: 20rpx;
		font-weight: 100;
		line-height: 1.5;
		color: #FFFFFF;
		background-color: #007AFF;
	}
	.item .icon{
		width: 80rpx;
		height: 80rpx;
	}
</style>
